package eteam.aps.systemservice.dal;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import eteam.aps.systeminterface.model.dto.ModuleoperDto;
import eteam.aps.systeminterface.model.entity.ModuleoperEntity;
import eteam.aps.systemservice.dal.mapper.IModuleoperMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 模块操作数据操作类
 */
@Service
public class ModuleoperDal {
    @Autowired
    private IModuleoperMapper moduleoperMapper;

    /**
     * 根据模块ID获取权限列表
     *
     * @param moduleId
     * @return
     */
    public List<ModuleoperEntity> getListByMId(String moduleId) {
        return moduleoperMapper.selectList(new QueryWrapper<ModuleoperEntity>().eq("FModuleId", moduleId)).stream().sorted(Comparator.comparing(ModuleoperEntity::getFopername)).collect(Collectors.toList());
    }

    /**
     * 根据角色ID获取权限列表
     *
     * @param roleId
     * @return
     */
    public List<ModuleoperEntity> getListByRoleId(String roleId) {
        return moduleoperMapper.selectList(new QueryWrapper<ModuleoperEntity>().inSql("FOperation", String.format("select distinct FOperation from sp_funacl where FUserId='%s'", roleId)));
    }

    /**
     * 获取已经设置【请求URL】的模块操作列表，此功能对应接口地址
     *
     * @return: 模块操作列表
     */
    public List<ModuleoperDto> getModuleopers() {
        return moduleoperMapper.getModuleopers();
    }
}